package com.vdf.sisconsolid.rest.definition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import com.vdf.sisconsolid.controller.StaffController;
import com.vdf.sisconsolid.rest.RestBase;
import com.vdf.sisconsolid.rest.requestresponsedata.FilterParameter;
import com.vdf.sisconsolid.rest.type.Staff;
import com.vdf.sisconsolid.rest.type.TipoServicio;

@Path("staff")
public class RestStaff extends RestBase {

	static Map responseStaff;
	static int countId = 3;
	static List<Staff> staffList = new ArrayList<Staff>();
	static {
		responseStaff = new HashMap();

		Staff staff1 = new Staff();
		staff1.setId(1L);
		staff1.setAddress1("Address1");
		staff1.setAddress2("Address2");
		staff1.setCity("City");
		staff1.setDob("2014-02-26");
		staff1.setFirstName("FirstName");
		staff1.setHireDate("2014-02-26");
		staff1.setLastName("LastName");
		staff1.setPhone("0351-4973425");
		staff1.setPosition(1L);
		staff1.setPostalCode("PostalCode");
		staff1.setState("State");
		staff1.setPositionValue("PositionValue");
		staff1.setActive(true);
		staffList.add(staff1);

		Staff staff2 = new Staff();
		staff2.setId(2L);
		staff2.setAddress1("Address12");
		staff2.setAddress2("Address22");
		staff2.setCity("City2");
		staff2.setDob("2014-02-26");
		staff2.setFirstName("FirstName2");
		staff2.setHireDate("2014-02-26");
		staff2.setLastName("LastName2");
		staff2.setPhone("0351-49734252");
		staff2.setPosition(1L);
		staff2.setPostalCode("PostalCode2");
		staff2.setState("State2");
		staff2.setPositionValue("PositionValue");
		staff2.setActive(true);
		staffList.add(staff2);
	}

	@GET
	@Produces("application/json")
	public Map<String, Object> get(@QueryParam("filter") String filters) {
		return StaffController.getResponseRest(staffList, filters);
	}

	@GET
	@Path("{id}")
	@Produces("application/json")
	public Map<String, Object> getById(@PathParam("id") Long id) {
		Staff staff = new Staff();
		staff.setId(id);
		return StaffController.getResponseRest(true, "infor", "loaded",
				staffList.get(staffList.indexOf(staff)));
	}

	@POST
	@Produces("application/json")
	public Map<String, Object> post(Staff staff) {
		staff.setId((long) countId++);
		return StaffController.saveAndResponse(staff, staffList);
	}

	@PUT
	@Path("{id}")
	@Produces("application/json")
	public Map<String, Object> put(@PathParam("id") long id, Staff staff) {
		// staffList.set(staffList.indexOf(staff), staff);
		return StaffController.updateAndResponse(staff, staffList);
	}

	@DELETE
	@Path("{id}")
	@Produces("application/json")
	public void delete(@PathParam("id") long id) {
		Staff cl = new Staff();
		cl.setId(id);
		staffList.remove(staffList.indexOf(cl));
	}

}
